<template>
	<view>
		<view class="goods-list">
			<view v-for="(v,i) in goodsList" :key="i" @click="gotoDetail(v)">
				<my-goods :v='v'></my-goods>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				queryObj:{
					cid:'',
					query:'',
					pagenum:1,
					pagesize:10
				},
				goodsList:[],
				total:0,
				isLoading:false
			}
		},
		methods: {
			getGoodsList(cb){
				this.isLoading=true
				uni.request({
					url:'https://api-hmugo-web.itheima.net/api/public/v1/goods/search',
					method:"GET",
					data:this.queryObj
				}).then(res=>{
					// console.log(res.data)
					this.isLoading=false
					this.total=res.data.message.total
					this.goodsList=[...this.goodsList,...res.data.message.goods]
					cb && cb()
				})
			},
			gotoDetail(v){
				uni.navigateTo({
					url:'/subpkg/good_detail/good_detail?goods_id='+v.goods_id
				})
			}
		},
		onReachBottom() {
			if(this.queryObj.pagenum*this.queryObj.pagesize>=this.total) return uni.showToast({
				title:'已经到底啦',
				icon:"loading"
			})
			if(this.isLoading) return ;
			this.queryObj.pagenum+=1;
			this.getGoodsList()
		},
		onPullDownRefresh() {
			this.queryObj.pagenum=1;
			this.total=0;
			this.goodsList=[];
			this.isLoading=false;
			this.getGoodsList(()=>uni.stopPullDownRefresh())
		},
		onLoad(options) {
			// console.log(options)
			this.queryObj.cid=options.cid || '';
			this.queryObj.query=options.query || '';
			// console.log(this.queryObj)
			this.getGoodsList()
		}
	}
</script>

<style>
.goods-list view{
	padding: 0 10rpx;
}
/* .goods-item{
	display: flex;
	justify-content: space-between;
	margin: 20rpx 0;
	background-color: #fff;
	border-radius: 16rpx;
	box-shadow: 4rpx 4rpx 4rpx #eee;
}

.goods-item-left image{
	width: 200rpx;
	height: 200rpx;
	display: block;
	margin-left: 10rpx;
}
.goods-item-right{
	flex-grow: 1;
	margin-left: 40rpx;
	padding: 10rpx;
	font-size: 24rpx;
	display: flex;
	justify-content: space-between;
	flex-direction: column;
}
.goods-item-right .goods-info-box{
	color: tomato;
	font-size: 32rpx;
} */
</style>
